<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .box {
            width: 400px;
            height: 300px;
            border: 1px solid black;
            text-align: center;
            margin-top: 200px;
            margin-left: 200px;
            border-radius: 10px;
        }

        .box input {
            width: 200px;
            height: 30px;
            font-size: 14px;
            margin: 5px;
            border-radius: 10px;
        }

        .box .in1 {
            margin-top: 30px;
        }

        .box .mima {
            font-size: 14px;
        }

        .box .zhu {
            width: 210px;
            margin-top: 40px;
            background-color: blue;
        }
    </style>
</head>
<body>
    <div class="box">
        <div class="zhuce">注册新账号</div>
        <input type="text" placeholder="请输入账号" class="in1">
        <br>
        <input type="password" placeholder="密码">
        <br>
        <input type="password" placeholder="确认密码">
        <br>
        <input type="button" value="注册" class="zhu">
    </div>
</body>
</html>
<script src="./promise封装ajax.js"></script>
<script>
    var ins = document.querySelectorAll('.box input')
    ins[3].onclick = function () {
        if (ins[0].value && ins[1].value) {
            if ((/^\d{4}$/.test(ins[1].value))&&(/^\d{4}$/.test(ins[1].value))){
                if (ins[1].value==ins[2].value) {
                    ajax('get', 'https://yantianfeng.com/api/register', { username: ins[0].value, password: ins[1].value }).then((data)=>{
                        // console.log(data);
                        // console.log(data.msg);
                        alert('注册成功')
                    })
                } else {
                    alert('两次密码不一致，请重新输入')
                }
            } else {
                alert('请输入正确的账号')
            }
        } else {
            alert('账号密码不能为空')
        }
    }
</script>